package com.gitee.elf.util

import taboolib.common.platform.function.info
import java.lang.reflect.Method

fun Class<*>.getMethodsByPrefix(prefix: String = ""): MutableList<Method> {
    val listOf = mutableListOf<Method>()

    for (method in declaredMethods) {
        if (prefix.isEmpty() || method.name.startsWith(prefix)) {
            listOf.add(method)
        }
    }
    if (this.superclass != Any::class.java) {
        listOf += this.superclass.getMethodsByPrefix(prefix)
    }
    return listOf
}

fun Class<*>.getDeepMethod(name: String): Method? {
    try {
        return getDeclaredMethod(name)
    } catch (e: Exception) {
        if (this.superclass != Any::class.java) {
            return superclass.getDeepMethod(name)
        }
    }
    return null
}